/*
 * Copyright 2008 The Apache Software Foundation Licensed under the Apache
 * License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package org.apache.ibatis.ibator.api;

import java.util.List;
import java.util.Properties;

import org.apache.ibatis.ibator.api.dom.java.Field;
import org.apache.ibatis.ibator.api.dom.java.Interface;
import org.apache.ibatis.ibator.api.dom.java.Method;
import org.apache.ibatis.ibator.api.dom.java.TopLevelClass;
import org.apache.ibatis.ibator.api.dom.xml.Document;
import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
import org.apache.ibatis.ibator.config.IbatorContext;

/**
 * This class includes no-operation methods for almost every method in the
 * IbatorPlugin interface. Clients may extend this class to implement some or
 * all of the methods in a plugin.
 * <p>
 * This adapter does not implement the <tt>validate</tt> method - all plugins
 * must perform validation.
 * 
 * @author Jeff Butler
 */
public abstract class IbatorPluginAdapter implements IbatorPlugin
{
	protected IbatorContext ibatorContext;
	protected Properties properties;

	public IbatorPluginAdapter()
	{
		properties = new Properties();
	}

	public IbatorContext getIbatorContext()
	{
		return ibatorContext;
	}

	public void setIbatorContext(IbatorContext ibatorContext)
	{
		this.ibatorContext = ibatorContext;
	}

	public Properties getProperties()
	{
		return properties;
	}

	public void setProperties(Properties properties)
	{
		this.properties.putAll(properties);
	}

	public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles()
	{
		return null;
	}

	public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
			IntrospectedTable introspectedTable)
	{
		return null;
	}

	public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles()
	{
		return null;
	}

	public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(
			IntrospectedTable introspectedTable)
	{
		return null;
	}

	public boolean daoCountByExampleMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoCountByExampleMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoDeleteByExampleMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoDeleteByExampleMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoDeleteByPrimaryKeyMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoDeleteByPrimaryKeyMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoImplementationGenerated(TopLevelClass topLevelClass,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoInsertMethodGenerated(Method method, Interface interfaze,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoInsertMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoInterfaceGenerated(Interface interfaze,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoSelectByExampleWithBLOBsMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoSelectByExampleWithBLOBsMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoSelectByExampleWithoutBLOBsMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoSelectByExampleWithoutBLOBsMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoSelectByPrimaryKeyMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoSelectByPrimaryKeyMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByExampleSelectiveMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByExampleSelectiveMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByExampleWithBLOBsMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByExampleWithBLOBsMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByExampleWithoutBLOBsMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByExampleWithoutBLOBsMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByPrimaryKeySelectiveMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByPrimaryKeySelectiveMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByPrimaryKeyWithBLOBsMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByPrimaryKeyWithBLOBsMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(
			Method method, Interface interfaze,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(
			Method method, TopLevelClass topLevelClass,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean modelExampleClassGenerated(TopLevelClass topLevelClass,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean modelFieldGenerated(Field field,
			TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
			IntrospectedTable introspectedTable,
			IbatorPlugin.ModelClassType modelClassType)
	{
		return true;
	}

	public boolean modelGetterMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
			IntrospectedTable introspectedTable,
			IbatorPlugin.ModelClassType modelClassType)
	{
		return true;
	}

	public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean modelRecordWithBLOBsClassGenerated(
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean modelSetterMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
			IntrospectedTable introspectedTable,
			IbatorPlugin.ModelClassType modelClassType)
	{
		return true;
	}

	public boolean sqlMapResultMapWithoutBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapCountByExampleElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapDeleteByExampleElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapDeleteByPrimaryKeyElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapDocumentGenerated(Document document,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapExampleWhereClauseElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapInsertElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapResultMapWithBLOBsElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapSelectByPrimaryKeyElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapUpdateByExampleSelectiveElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapUpdateByExampleWithBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapUpdateByExampleWithoutBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapUpdateByPrimaryKeySelectiveElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(
			XmlElement element, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapInsertSelectiveElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoInsertSelectiveMethodGenerated(Method method,
			Interface interfaze, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean daoInsertSelectiveMethodGenerated(Method method,
			TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
	{
		return true;
	}

	public void initialized(IntrospectedTable introspectedTable)
	{
	}

	public boolean sqlMapBaseColumnListElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public boolean sqlMapBlobColumnListElementGenerated(XmlElement element,
			IntrospectedTable introspectedTable)
	{
		return true;
	}

	public void addSetterComment(Method method, String doc, String paramName)
	{
		StringBuilder sb = new StringBuilder();
		if (doc != null && doc.length() != 0)
		{
			method.addJavaDocLine("/**");
			sb.append(" * @param " + paramName + " ");
			doc = doc.replaceAll("\n", "<br>\n\t * ");
			sb.append(doc);
			method.addJavaDocLine(sb.toString());
			method.addJavaDocLine(" */");
		}
	}

	public void addFieldComment(Field field, String doc)
	{
		StringBuilder sb = new StringBuilder();
		if (doc != null && doc.length() != 0)
		{
			field.addJavaDocLine("/**");
			sb.append(" * ");
			doc = doc.replaceAll("\n", "<br>\n\t * ");
			sb.append(doc);
			field.addJavaDocLine(sb.toString());
			field.addJavaDocLine(" */");
		}
	}

	public void addGetterComment(Method method, String doc, String paramName)
	{
		StringBuilder sb = new StringBuilder();
		if (doc != null && doc.length() != 0)
		{
			method.addJavaDocLine("/**");
			sb.append(" * @return ");
			doc = doc.replaceAll("\n", "<br>\n\t * ");
			sb.append(doc);
			method.addJavaDocLine(sb.toString());
			method.addJavaDocLine(" */");
		}
	}

	public void addMethodComment(Method method, String doc, String paramName)
	{
		StringBuilder sb = new StringBuilder();
		if (doc != null && doc.length() != 0)
		{
			method.addJavaDocLine("/**");
			sb.append(" * ");
			doc = doc.replaceAll("\n", "<br>\n\t * ");
			sb.append(doc);
			method.addJavaDocLine(sb.toString());
			method.addJavaDocLine(" */");
		}
	}
}
